home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / 3D Buttons CDEF 1.0b6 / Source / 3D Buttons CDEF source / (3D CDEF++.68k.π) / StSaveFont.cp < prev    next >
Text File  |  1994-12-28  |  1KB  |  73 lines

  1. /*
  2.     Public domain by Zig Zichterman.
  3. */
  4. /*
  5.     StSaveFont
  6.     
  7.     A class that saves the current port's font, size, style and mode on
  8.     construction and restores on destruction
  9.     
  10.     12/27/94    zz    h    initial write
  11. */
  12. #include "StSaveFont.h"
  13.  
  14. #include <QuickDraw.h>
  15.  
  16. StSaveFont::StSaveFont(void)
  17. {
  18.     // init to something boring
  19.     mFont = mSize = mStyle = mMode = 0;
  20.     
  21.     // save the current port's font settings
  22.     Save();
  23. }
  24.  
  25. StSaveFont::~StSaveFont()
  26. {
  27.     // restore the current port to what it was when we last Save()d
  28.     Restore();
  29. }
  30.  
  31. void
  32. StSaveFont::Save(void)
  33. {
  34.     // get the current port
  35.     GrafPtr    currentPort    = NULL;
  36.     ::GetPort(¤tPort);
  37.     if (currentPort == NULL) {
  38.         return;
  39.     }
  40.     
  41.     // get the text settings
  42.     mFont    = currentPort->txFont;
  43.     mSize    = currentPort->txSize;
  44.     mStyle    = currentPort->txFace;
  45.     mMode    = currentPort->txMode;
  46.     
  47. }
  48.  
  49. void
  50. StSaveFont::Restore(void) const
  51. {
  52.     // restore 'em
  53.     ::TextFont(mFont);
  54.     ::TextSize(mSize);
  55.     ::TextFace(mStyle);
  56.     ::TextMode(mMode);
  57. }
  58.  
  59. /**************************************************************************
  60.     SystemFont()                                    [public, static]
  61.     
  62.     Force the current port's font to system font, default size,
  63.     plain, srcCopy. 
  64. **************************************************************************/
  65. void
  66. StSaveFont::SystemFont(void)
  67. {
  68.     ::TextFont(0);
  69.     ::TextSize(0);
  70.     ::TextFace(0);
  71.     ::TextMode(srcCopy);
  72. }
  73.